<div id="app">
    <admin-page-header>
        <bi-button icon="fa-plus" type="primary" @click="edit()">添加</bi-button>
    </admin-page-header>
    <div class="container">
        <div class="row gap-3">
            <div class="col-12">
                <bi-card title="消费等级">
                    <bi-table :loading="consumeLoading" :data="consumeList" min-height="200" @dragsort="dragsort" item-key="level_id" dragsort  >
                        <bi-table-column label="ID" name="level_id"  width="50" ></bi-table-column>
                         <bi-table-column label="等级" name="title"  ></bi-table-column>
                        <bi-table-column label="消费金额" name="amount" width="100" ></bi-table-column>
                        <bi-table-column label="操作" width="200" >
                            <template #default="scope">
                                <bi-button icon="fa-edit" @click="edit(scope.row)" type="primary" >编辑</bi-button>
                                <bi-button icon="fa-trash" @click="del(scope.row)" type="warning" >删除</bi-button>
                            </template>
                        </bi-table-column>
                    </bi-table>
                </bi-card>
            </div>
            <!--
            <div class="col-12"  >
                <bi-card title="特殊等级">
                    <bi-table :loading="specialLoading" :data="specialList"  min-height="200" >
                        <bi-table-column label="ID" name="level_id"  width="50" ></bi-table-column>
                        <bi-table-column label="等级" name="title"  ></bi-table-column>
                        <bi-table-column label="操作" width="200" >
                            <template #default="scope">
                                <bi-button icon="fa-edit" @click="edit(scope.row)" type="primary" >编辑</bi-button>
                                <bi-button icon="fa-trash" @click="del(scope.row)" type="warning" >删除</bi-button>
                            </template>
                        </bi-table-column>
                    </bi-table>
                </bi-card>
            </div>
            -->
        </div>
    </div>
</div>


<script>
import editDialog from 'memberlevel/edit-dialog.vue';
    let app = admin.createApp({
        components:{
        },
        data(){
             
            return {
                consumeLoading:false,
                specialLoading:false,
                consumeList:[],
                specialList:[]
            }
        },
        methods:{
            edit(item){
                this.$dialog({
                    title: item ? '编辑['+item.title+']' : '添加会员等级',
                    type:'vue',
                    content:admin.createApp(editDialog,{item}),
                    callback:(type)=>{
                        if (type=='consume') this.getConsumeList();
                       // if (type=='special') this.getSpecialList();
                    }
                })
            },
            getConsumeList(){
                this.consumeLoading = true;
                this.$ajax({
                    url:this.$url({action:'list'}),
                    data:{
                        type:'consume'
                    },
                    success:(res)=>{
                        this.consumeLoading = false;
                        this.consumeList = res;
                    }
                })
            },
            getSpecialList(){
                this.specialLoading = true;
                this.$ajax({
                    url:this.$url({action:'list'}),
                    data:{
                        type:'special'
                    },
                    success:(res)=>{
                        this.specialLoading = false;
                        this.specialList = res;
                    }
                })
            },
            del(item){
                this.$loading();
                this.$confirm('确定要删除吗',()=>{
                    this.$ajax({
                        url:this.$url({action:'del'}),
                        data:{
                            level_id:item.level_id
                        },
                        success:(res)=>{
                            this.$toast('删除成功');
                            if (item.type=='consume') this.getConsumeList();
                           // if (item.type=='special') this.getSpecialList();
                        },
                        over:()=>{
                            this.$loading(false);
                        }
                    })
                });
            },
            dragsort(value){
                this.$loading();
                this.$ajax({
                    url:this.$url({action:'sort'}),
                    data:{
                        ids:value
                    },
                    success:(data)=>{
                        this.$loading(false)
                    }
                });
            }
        },
        mounted(){
            this.getConsumeList();
            //this.getSpecialList();
        }
    }).mount('#app');
</script>